from sqlalchemy import Column, Integer, ForeignKey, PrimaryKeyConstraint, BigInteger
from sqlalchemy.orm import relationship
from models.base import Base
metadata = Base.metadata

class SysRoleMenu(Base):
    __tablename__ = 'sys_role_menus'

    role_id = Column(Integer, ForeignKey('sys_roles.id'), nullable=False, comment='角色ID')
    menu_id = Column(Integer, ForeignKey('admin_menus.id'), nullable=False, comment='菜单ID')

    __table_args__ = (
        PrimaryKeyConstraint('role_id', 'menu_id'),
    )

    admin_menu = relationship('AdminMenu', back_populates='role_menus')
    role = relationship('SysRole', back_populates='role_menus')

    def __repr__(self):
        return f"<SysRoleMenu(role_id={self.role_id}, menu_id={self.menu_id})>"
